import {getReportListApi, getReportDetailApi, getDatasetDataApi, getFilterValueApi} from "@/api/publicReportManage";


const reportManage = {
	namespaced: true,
	actions: {
		getReportList ({ commit }, props){
			return new Promise((resolve, reject) => {
				getReportListApi(props.id, props.key)
					.then(res => {
						if (res.code === 0) {
							resolve(res)
						} else {
							reject(res.msg)
						}
					})
					.catch(err => {
						reject(err)
					})
			})
		},

		getReportDetail({ commit }, props){
			return new Promise((resolve, reject) => {
				getReportDetailApi(props.id, props.key)
					.then(res => {
						if (res.code === 0) {
							resolve(res)
						} else {
							reject(res)
						}
					})
					.catch(err => {
						reject(err)
					})
			})
		},

		getDatasetData({ commit }, props){
			return new Promise((resolve, reject) => {
				getDatasetDataApi(props.id, props.key, props.filter)
					.then(res => {
						if (res.code === 0) {
							resolve(res)
						} else {
							reject(res.msg)
						}
					})
					.catch(err => {
						reject(err)
					})
			})
		},

		getFilterValue({ commit }, props){
			return new Promise((resolve, reject) => {
				getFilterValueApi(props.reportId, props.id, props.query)
					.then(res => {
						if (res.code === 0) {
							resolve(res)
						} else {
							reject(res.msg)
						}
					})
					.catch(err => {
						reject(err)
					})
			})
		}
	}
}

export default reportManage
